package com.qingcheng.dao;

import com.qingcheng.pojo.goods.Sku;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

public interface SkuMapper extends Mapper<Sku> {

    /**
     * 已下架商品总数
     * @return
     */
    @Select("SELECT COUNT(id) FROM tb_sku WHERE num<=alert_num")
    public int findAlertNum();

    /**
     * 按照商品状态查询总数
     * @param status
     * @return
     */
    @Select("SELECT COUNT(id) FROM tb_sku WHERE STATUS= #{status}")
    public int findGoodsNum(@Param("status")String status);

    /**
     * 查询所有商品数量
     * @return
     */
    @Select("SELECT COUNT(id) FROM tb_sku")
    public int selectAllNum();

    /**
     * 商品下架广播通知
     */
    //商品下级逻辑
    @Update("UPDATE tb_sku SET status=2 WHERE id=#{id}")
    void isDelete(@Param("id") String id);

    /**
     * 修改商品为上架后为elasticsearch插入数据
     */
    @Update("UPDATE tb_sku set status=1 WHERE id=#{id}")
    void isUpdate(@Param("id") String id);

    @Select("update tb_sku set num = num - #{num} where id = #{id}")
    public void deductionStock(@Param("id") String id,@Param("num") Integer num);

    @Select("update tb_sku set sale_num = sale_num + #{num} where id = #{id}")
    public void addSaleNum(@Param("id") String id, @Param("num") Integer num );

}
